<!-- 表格组件 -->
<template>
  <div class="container-user">
    <Search />
    <el-table style="width: 100%" :data="getUserList" v-loading="getLoading">
      <el-table-column label="#" width="80" type="index"
      :index="( getPager.currentPage -1 ) * getPager.pageSize + 1"></el-table-column>
      <el-table-column label="UID" width="120">
        <template slot-scope="scope">
          <!-- scope.row:每一条记录 -->
          <span>{{ scope.row.uid }}</span>
        </template>
      </el-table-column>
      <el-table-column label="账号" width="130">
        <template slot-scope="scope">
          <span>{{ scope.row.account }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" width="120">
        <template slot-scope="scope">
          <el-tag :type="statusList[scope.row.status].type">
            <span><i :class="statusList[scope.row.status].icon"></i> {{ statusList[scope.row.status].label}}</span>
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="昵称" width="180">
        <template slot-scope="scope">
          <span>{{ scope.row.nickname }}</span>
        </template>
      </el-table-column>
      <el-table-column label="角色" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.role }}</span>
        </template>
      </el-table-column>
      <el-table-column label="手机" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.phone }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button v-has:delete="$route" size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import Search from './search'
// import { mapGetters , mapMutations } from "vuex";
// 导入混入对象（可以包含组件中声明的各个参数项）
import systemUser from '@/mixins/systemUser'
export default {
  mixins: [systemUser],
  props: ['status'],
  components: {
    Search
  },
  data () {
    return {
      statusList: [
        { label: '待激活', icon: 'el-icon-time', type: 'primary' },
        { label: '正常', icon: 'el-icon-success', type: 'success' },
        { label: '已锁定', icon: 'el-icon-lock', type: 'warning' },
        { label: '已停用', icon: 'el-icon-warning', type: 'danger' },
        { label: '已注销', icon: 'el-icon-delete', type: 'info' }
      ]
    }
  },
  computed: {

  },
  methods: {
    handleEdit (index, item) {
      // this.setCurrentUser(item) // 保存当前编辑用户的信息
      this.$router.push('/dashboard/system/user/edit/' + item.uid)
    },
    handleDelete (index, item) {
      // console.log('删除操作。。',row)
      this.$confirm('此操作将删除该账号, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$http.removeSystemUser({uid: item.uid}).then(res => {
          console.log(res)
          if (res && res.data.code === 200) {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.load()
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
  }
}
</script>

<style scoped lang="less">
// .el-table{
//   position: relative;
//   height:500px;
//   overflow: auto;
// }
</style>
